<?php

/**
 * @author: Tran Tuan
 * @email : trantuanckc@gmail.com
 * This is the model class for table "nguoitimviec".
 *
 * The followings are the available columns in table 'nguoitimviec':
 * @property integer $id
 * @property integer $thanhpho_id
 * @property string $tendangnhap
 * @property string $matkhau
 * @property string $tengoi
 * @property string $email
 * @property integer $gioitinh
 * @property string $ngaysinh
 * @property integer $tinhtranghonnhan
 * @property string $dienthoaiban
 * @property string $dtdd
 * @property string $avatar
 * @property integer $status
 * @property string $last_login
 * @property string $create_date
 * @property string $active_code
 * @property integer $role
 */
class Nguoitimviec extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Nguoitimviec the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'nguoitimviec';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('diachi,thanhpho_id,quocgia_id , tendangnhap, matkhau, email, gioitinh, ngaysinh', 'required'),
            array('tendangnhap', 'length', 'max' => 45),
            array('matkhau, active_code', 'length', 'max' => 32),
            array('tengoi, email', 'length', 'max' => 50),
            array('dienthoaiban, dtdd', 'length', 'max' => 14),
            array('avatar', 'length', 'max' => 255),
            array('last_login, create_date', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, thanhpho_id, tendangnhap, matkhau, tengoi, email, gioitinh, ngaysinh, tinhtranghonnhan, dienthoaiban, dtdd, avatar, status, last_login, create_date, active_code, role', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'thanhpho' => array(self::BELONGS_TO, 'Thanhpho', 'thanhpho_id'),
            'quocgia' => array(self::BELONGS_TO, 'Quocgia', 'quocgia_id')
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'thanhpho_id' => 'Thành phố',
            'quocgia_id' => 'Quốc gia',
            'tendangnhap' => 'Tên đăng nhập',
            'matkhau' => 'Mật khẩu',
            'tengoi' => 'Họ & Tên',
            'email' => 'Email',
            'gioitinh' => 'Giới tính',
            'ngaysinh' => 'Ngày sinh',
            'tinhtranghonnhan' => 'Tình trạng hôn nhân',
            'dienthoaiban' => 'Điện thoại',
            'dtdd' => 'Điện thoại di động',
            'avatar' => 'Avatar',
            'status' => 'Status',
            'last_login' => 'Last Login',
            'create_date' => 'Create Date',
            'active_code' => 'Active Code',
            'role' => 'Role',
            'diachi'=> 'Địa chỉ'
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('thanhpho_id', $this->thanhpho_id);
        $criteria->compare('tendangnhap', $this->tendangnhap, true);
        $criteria->compare('matkhau', $this->matkhau, true);
        $criteria->compare('tengoi', $this->tengoi, true);
        $criteria->compare('email', $this->email, true);
        $criteria->compare('gioitinh', $this->gioitinh);
        $criteria->compare('ngaysinh', $this->ngaysinh, true);
        $criteria->compare('tinhtranghonnhan', $this->tinhtranghonnhan);
        $criteria->compare('dienthoaiban', $this->dienthoaiban, true);
        $criteria->compare('dtdd', $this->dtdd, true);
        $criteria->compare('avatar', $this->avatar, true);
        $criteria->compare('status', $this->status);
        $criteria->compare('last_login', $this->last_login, true);
        $criteria->compare('create_date', $this->create_date, true);
        $criteria->compare('active_code', $this->active_code, true);
        $criteria->compare('role', $this->role);

        $criteria->with = array(
            'with' => array('quocgia','thanhpho')
        );

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}